const request = require("miniapp-request");
const store = require('../../libs/storage');

global.Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		isLoaded: false,
		nick_name: '',
		regionList: [],
		finishedCgtCount: 0,
		finishedCgt: 'no',
		finishedKpt: 'no',
		mapBgImageWidth: 750,
		mapBgImageHeight: 1061,
		windowWidth: 721,
		balloonXRatio: 1,
	},
	onLoad: function (options) {
        console.log("============startTest:onLoad");
        console.log(options);
		const windowInfo = wx.getWindowInfo();
		this.setData({
			nick_name: options.nick_name ? options.nick_name : '',
			windowWidth: windowInfo.windowWidth,
			balloonXRatio: windowInfo.windowWidth / this.data.mapBgImageWidth,
		});
	},
	onShow: function () {
        console.log("============startTest:onShow");
		request({
			url: '/index/Qa/regionListForMap.html',
			data: {
				nick_name: this.data.nick_name
			},
			method: 'POST'
		}).then(res => {
            console.log("============startTest:request");
			wx.hideLoading();
			const {
				code,
				msg,
				data
			} = res.data
			if (code >= 0) {
				this.setData({
					regionList: data.regionList,
					finishedCgtCount: data.finishedCgtCount,
					finishedCgt: data.finishedCgt,
					finishedKpt: data.finishedKpt,
				});
			} else {
				wx.showModal({
					title: '提示',
					content: msg,
					showCancel: false,
				});
			}

			this.setData({
				loading: false
			});
		})
	},
})